package com.gaussian.property.admin.module.system.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.songqi.common.core.domain.R;
import com.songqi.common.core.domain.page.PageDomain;
import com.songqi.common.core.domain.page.PageDataInfo;
import com.songqi.common.log.annotation.Log;
import com.gaussian.property.module.system.enums.BusinessType;
import com.songqi.common.web.request.controller.BaseController;
import com.gaussian.property.module.system.entity.SysNotice;
import com.gaussian.property.module.system.service.ISysNoticeService;
import com.gaussian.property.module.system.vo.SysNoticeAddVo;
import com.gaussian.property.module.system.vo.SysNoticeDetailVo;
import com.gaussian.property.module.system.vo.SysNoticeEditVo;
import com.gaussian.property.module.system.vo.SysNoticeQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 公告 信息操作处理
 *
 * @author songqi(13776346982)
 */
@RestController
@RequestMapping("/system/notice")
@Api(tags = "公告管理")
@Validated
public class SysNoticeController extends BaseController
{
    @Resource
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public R<PageDataInfo<SysNotice>> pageListNotice(SysNoticeQueryVo queryVo, PageDomain pageDomain)
    {
        IPage<SysNotice> page = noticeService.pageListNotice(queryVo, pageDomain, getLanguage());
        return getReturnDataTableInfo(page);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public R<SysNoticeDetailVo> getInfo(@PathVariable String noticeId)
    {
        return R.success(noticeService.selectNoticeById(Long.valueOf(noticeId)));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody SysNoticeAddVo sysNoticeAddVo) throws IOException {
        noticeService.insertNotice(sysNoticeAddVo);
        return success();
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@Validated @RequestBody SysNoticeEditVo sysNoticeEditVo)
    {
        noticeService.updateNotice(sysNoticeEditVo);
        return success();
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public R remove(@PathVariable Long[] noticeIds)
    {
        noticeService.deleteNoticeByIds(noticeIds);
        return success();
    }
}
